import time
from io import BytesIO

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()

# 图片爬取
driver.get("https://pic.netbian.com/4kdongman/")

all_size = driver.get_window_size()


imgs = driver.find_elements(By.XPATH, '//ul[@class="clearfix"]/li/a/img')
# for img in imgs:
#     src = img.get_attribute('src')
#     print(src)

imgs_ = imgs[1]
size = imgs_.size
location = imgs_.location

print("图1大小:%s" % imgs_.size)
print("图1边界信息:%s" % imgs_.location)

from PIL import Image

top, bottom, left, right = location['y'], location['y'] + size['height'], location['x'], location['x'] + size['width']
screen = driver.get_screenshot_as_png()
screen = Image.open(BytesIO(screen))
cap = screen.crop((left, top, right, bottom))
cap.save('11.png')

time.sleep(15)
driver.close()
